package fr.charlott.batch;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;

public class SimpleStepExecutionListener implements StepExecutionListener {

    private boolean passedBefore = false;

    private boolean passedAfter = false;

    private StepExecution stepExecution = null;

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.batch.core.StepExecutionListener#beforeStep(org.
     * springframework.batch.core.StepExecution)
     */
    public void beforeStep(StepExecution stepExecution) {
        passedBefore = true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.batch.core.StepExecutionListener#afterStep(org.
     * springframework.batch.core.StepExecution)
     */
    public ExitStatus afterStep(StepExecution stepExecution) {
        passedAfter = true;
        this.stepExecution = stepExecution;
        if (stepExecution.getJobParameters().getString("specificCondition", null) != null) {
            return new ExitStatus("SPECIFIC EXIT STATUS");
        } else {
            this.stepExecution = stepExecution;
            return stepExecution.getExitStatus();
        }
    }

    public boolean isPassedBefore() {
        return passedBefore;
    }

    public boolean isPassedAfter() {
        return passedAfter;
    }

    public StepExecution getStepExecution() {
        return stepExecution;
    }

}
